package com.sunshine.litemusic.activity.main;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.sunshine.litemusic.fragment.music.MusicFragment;
import com.sunshine.litemusic.fragment.recommend.RecommendFragment;
import com.sunshine.litemusic.fragment.search.SearchFragment;

import java.util.ArrayList;

/**
 * @author sunshine
 * @date 2020/5/29
 * 主活动viewpager适配器
 */
public class MainAdapter extends FragmentPagerAdapter {

    private ArrayList<Fragment> fragmentList;

    MainAdapter(@NonNull FragmentManager fm) {
        super(fm);
        fragmentList = new ArrayList<>();
        SearchFragment recommend = new SearchFragment();
        recommend.setSearch(false);
        fragmentList.add(recommend);
        fragmentList.add(new MusicFragment());
        fragmentList.add(new SearchFragment());
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    ArrayList<Fragment> getFragmentList() {
        return fragmentList;
    }
}
